package com.anhry.app.safety.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.anhry.app.safety.manage.system.bean.TbUser;
import com.anhry.app.safety.manage.system.service.SystemService;
import com.anhry.app.safety.util.ContextPvd;
import com.anhry.app.safety.util.Util;
import com.anhry.app.safety.util.UtilMethod;

public class PermissionTag extends TagSupport
{
  private static final long serialVersionUID = 1L;
  private String module;
  private int permissionType;
  private SystemService systemService = (SystemService)UtilMethod.getSpringContext().getBean("systemServiceImpl");
  private ContextPvd contextPvd = (ContextPvd)UtilMethod.getSpringContext().getBean("contextPvdImpl");

  public String getModule() {
    return this.module;
  }
  public void setModule(String module) {
    this.module = module;
  }

  public int getPermissionType() {
    return this.permissionType;
  }

  public void setPermissionType(int permissionType) {
    this.permissionType = permissionType;
  }

  public int doStartTag() throws JspException {
		boolean result = false;
		try {
			TbUser user = (TbUser) this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			if ((this.systemService.hasPermissionByFunCode(user, this.module,this.permissionType))) {
				result = true;
			}

			return (result) ? 1 : 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
}

